<?php

namespace common\models\base;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use mootensai\behaviors\UUIDBehavior;

/**
 * This is the base model class for table "dictionary".
 *
 * @property string $code
 * @property string $value
 * @property string $label
 * @property string $mnemonic
 * @property integer $order_num
 * @property string $parent_id
 * @property integer $level
 *
 * @property \common\models\DictionaryType $dictionaryType
 */
class Dictionary extends \common\hayz\db\ActiveRecord
{
    use \mootensai\relation\RelationTrait;

    private $_rt_softdelete;
    private $_rt_softrestore;

    public function __construct(){
        parent::__construct();
        $this->_rt_softdelete = [
            'deleted_by' => \Yii::$app->user->id,
            'deleted_at' => date('Y-m-d H:i:s'),
        ];
        $this->_rt_softrestore = [
            'deleted_by' => 0,
            'deleted_at' => date('Y-m-d H:i:s'),
        ];
    }

    /**
    * This function helps \mootensai\relation\RelationTrait runs faster
    * @return array relation names of this model
    */
    public function relationNames()
    {
        return [
            'dictionaryType'
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['code', 'value'], 'required'],
            [['order_num', 'level'], 'integer'],
            [['code', 'parent_id'], 'string', 'max' => 32],
            [['value'], 'string', 'max' => 50],
            [['label'], 'string', 'max' => 200],
            [['mnemonic'], 'string', 'max' => 45]
        ];
    }

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'dictionary';
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'code' => '类型',
            'value' => '值',
            'label' => '显示名称',
            'mnemonic' => '助记码',
            'order_num' => '排序',
            'parent_id' => '上级序号',
            'level' => '层级',
        ];
    }
    
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDictionaryType()
    {
        return $this->hasOne(\common\models\DictionaryType::className(), ['code' => 'code']);
    }
    

}
